package com.huitone.smspfm.oldclient.asclient.resp;

import java.io.File;
import java.io.IOException;

import com.bin.common.utils.FileUtils;
import com.bin.common.utils.StringUtils;
import com.huitone.smspfm.context.utils.ContextPropertiesUtils;
import com.huitone.smspfm.oldclient.core.TestFileWriter;
import com.huitone.smspfm.oldclient.model.RespSms;

/**   
* @Title RespFileWriter.java 
* @Package com.huitone.smspfm.oldclient.module.resp 
* @Description TODO(用一句话描述该文件做什么) 
* @author ybliang   
* @date 2017年5月25日 下午5:45:14 
* @version V1.0   
*/
public class RespFileWriterForMultiAccount extends TestFileWriter {
	
	//private final static ExtLogger logger = ExtLogger.create(RespFileWriter.class);
	
	private String moFileDir = null;
	private String dvFileDir = null;
	
	public RespFileWriterForMultiAccount() {
		
		this.setLineToCut(StringUtils.toLongP(ContextPropertiesUtils.getProperty("resp.file.maxsplit.rowcount"), 1000));
		this.setTimeToCut(StringUtils.toLongP(ContextPropertiesUtils.getProperty("resp.file.maxsplit.interal"), 60 * 1000));
		this.setWrapLeft("<data>");
		this.setWrapRight("</data>");
		
		moFileDir = ContextPropertiesUtils.getProperty("smspfm.client.file.dir.resp");
		
		//this.setFilePath(moFileDir);
		//this.setFileName("resp.tmp");
		//this.setCutFileName(this.new CutFileNameCofig("resp_", ".xml"));
		//this.init();
		//this.enableWatchDog();
		
	}

	public RespFileWriterForMultiAccount(String filePath, String fileName) {
		super(filePath, fileName);
	}
	
	@Override
	public synchronized void write(Object obj) throws IOException {
		
		if (obj == null) {
			return;
		}
		
		if (obj instanceof RespSms) {
			
			RespSms respSms = (RespSms) obj;
			
			if (dvFileDir == null) {
				dvFileDir = FileUtils.createDir(moFileDir + File.separator + respSms.getClientname() + File.separator + "resp").getAbsolutePath();
				this.setFilePath(dvFileDir);
				this.setFileName("resp.tmp");
				this.setCutFileName(this.new CutFileNameCofig("resp_", ".xml"));
				this.init();
				this.enableWatchDog();
			}
			
			writeLine(respSms.toString());
			
		}
	}

}
